package com.xianxian.user.controller;

import com.xianxian.user.entity.User;
import com.xianxian.user.model.dto.UserDTO;
import com.xianxian.user.model.vo.UserVO;
import com.xianxian.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述：
 *
 * @author zhang
 *
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public List<UserDTO> getUserList(@RequestParam(value = "userName",required = false) String userName){
        return userService.getUserList(userName);
    }

    @PostMapping("/saveUser")
    public String saveUser(@RequestBody UserVO userVO){
        return userService.saveUser(userVO);
    }

    @PutMapping("/updateUser")
    public String updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }

    @DeleteMapping("/deleteById/{id}")
    public String deleteUserById(@PathVariable("id") String id){
        boolean flag = userService.removeById(id);
        if(flag){
            return "数据删除成功";
        }else{
            return "数据删除失败";
        }
    }




}
